import 'package:flutter/material.dart';
import 'package:r_calendar/r_calendar.dart';

class CalendarModal {
  static show({BuildContext context, date, onChange}) {
    RCalendarController controller = RCalendarController.single(
      selectedDate: date,
      isAutoSelect: false,
    );

    showDialog(
      context: context,
      builder: (context) {
        return AlertDialog(
          title: Text(
            '选择日期',
            style: TextStyle(
              color: Colors.black,
              fontSize: 20,
            ),
          ),
          content: SingleChildScrollView(
            child: Container(
              width: MediaQuery.of(context).size.width,
              child: Column(
                children: [
                  RCalendarWidget(
                    controller: controller,
                    customWidget: DefaultRCalendarCustomWidget(),
                    firstDate: DateTime(1970, 1, 1),
                    lastDate: DateTime(2055, 12, 31),
                  ),
                  Row(
                    children: [
                      Expanded(
                        child: InkWell(
                          child: Container(
                            padding: EdgeInsets.all(10),
                            child: Center(
                              child: Text('取消'),
                            ),
                          ),
                          onTap: () {
                            Navigator.of(context).pop();
                          },
                        ),
                      ),
                      Expanded(
                        child: InkWell(
                          child: Container(
                            padding: EdgeInsets.all(10),
                            child: Center(
                              child: Text(
                                '确定',
                                style: TextStyle(color: Colors.blue),
                              ),
                            ),
                          ),
                          onTap: () {
                            onChange(controller.selectedDate);
                            Navigator.of(context).pop();
                          },
                        ),
                      ),
                    ],
                  )
                ],
              ),
            ),
          ),
        );
      },
    );
  }
}
